package com.mjf.datatype;

/**
 * 引用数据类型：类、接口、数组
 *
 * -多态：
 *  属性看编译类型（编译类型看左）
 *  方法看运行类型（运行类型看右）
 */
public class ClassUse {

    public static void main(String[] args) {

        Cylinder cylinder = new Cylinder();
        System.out.println(cylinder);
        cylinder.setLength(10);
        double volume = cylinder.findVolume();
        System.out.println(volume);
        double area = cylinder.findArea();
        System.out.println(area);

    }
}

//--圆
class Circle{
    //--半径
    private double radius;

    public Circle() {
        radius = 1;
    }

    public double getRadius() {
        return radius;
    }

    public void setRadius(double radius) {
        this.radius = radius;
    }

    //--圆的面积
    public double findArea(){
        return Math.PI * radius * radius;
    }
}

//--圆柱
class Cylinder extends Circle{

    private double length;

    public Cylinder() {
        length = 1;
    }

    public double getLength() {
        return length;
    }

    public void setLength(double length) {
        this.length = length;
    }

    //--圆柱的体积
    public double findVolume(){
        return super.findArea() * length;
    }

    //--圆柱的表面积
    public double findArea(){
        return 2 * Math.PI * super.getRadius() * this.length + 2 * super.findArea();
    }

    @Override
    public String toString() {
        return "Cylinder{" +
                "length=" + length +
                '}';
    }
}

